﻿@{
    ViewBag.Title = "Form"; 
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'laydate', 'common','optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common,
            laydate = layui.laydate;
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        //此处需修改
        //类型为时间时
        //laydate.render({
            //elem: '#F_Birthday'
            //, btns: ['clear', 'now']
            //, trigger: 'click',
            //format: 'yyyy-MM-dd',
        //});
          laydate.render({
                 elem: '#F_EndDate'
                 , btns: ['clear', 'now']
                 , trigger: 'click',
                 format: 'yyyy-MM-dd',
             });
                laydate.render({
                  elem: '#F_StartDate'
                  , btns: ['clear', 'now']
                  , trigger: 'click',
                  format: 'yyyy-MM-dd',
              });
        $(function () {
            initControl();
            if (!!keyValue) {
                 common.ajax({
                   url: '/AttendanceManagement/Holiday/GetFormJson',
                   dataType: 'json',
                   data: { keyValue: keyValue },
                   async: false,
                   success: function (data) {
                       common.val('adminform', data);
                    }
               });
           }
           form.render();
       });
       wcLoading.close();

       function initControl() {
           //此处需修改
           //绑定数据源
           //类型为下拉框时
             $("#F_DutyId").bindSelect({
                 url: "/SystemOrganize/Duty/GetListJson",
                 id: "F_Id",
                 text: "F_FullName"
             });
                $("#F_HolidayTypeId").bindSelect({
                   url: "/AttendanceManagement/Holidaytype/GetListJson",
                id: "F_Id",
                 text: "F_FullName"
               });

       }


       //监听提交
       form.on('submit(saveBtn)', function (data) {
           var postData = data.field;

             common.ajax({
                    url: '/AttendanceManagement/Holiday/GetSumJson',
                    dataType: 'json',
                        data: { userid: postData["F_UserId"],
                         holidaytypeid:postData["F_HolidayTypeId"],
                         day:postData["F_Days"]
                         },
                    async: false,
                    success: function (data) {
                        if(data==true){
                          common.modalMsg("请假天数超过剩余天数，或者假期已经用完，不能请假！", "warning");
                          return false;
                        }else{

                              common.submitForm({
                url: '/AttendanceManagement/Holiday/SubmitForm?keyValue=' + keyValue,
                param: postData,
                success: function () {
                    common.parentreload('data-search-btn');
                }
            })
                        }
                          
                     }
                });





          
           return false;
       });
   });
       function search(fileds) {
         layui.use(['jquery', 'form', 'common'], function () {
             var form = layui.form,
                 $ = layui.$,
                 common = layui.common;
             //不同弹窗
              if (fileds == '部门') {
                 common.modalOpen({
                     title: "选择组织",
                     url: "/SystemOrganize/Organize/AddForm?name=" + "F_OrganizeName" + "&value=" + "F_OrganizeId" + "&ids=" + $('#F_OrganizeId').val() + "&managerkey=" + $('#F_ManagerId').val() + "&managername=" + $('#F_ManagerName').val(),
                     width: "650px",
                     height: "600px",
                 });
             }
             else   if (fileds == '人员') {
                    common.modalOpen({
                        title: "选择人员",
                            url: "/SystemOrganize/User/AddForm3?name=" + "F_RealName" + "&num="+"F_UserNum"+"&value=" + "F_UserId" + "&ids=" + $('#F_UserId').val(),
                        width: "650px",
                        height: "600px",
                    });
                 }
             else {
                 return false;
             }
         });
     }
          
            function  change(){
    if($("#F_EndDate").val()!=""&&$("#F_StartDate").val()!=""){

                   $("#F_Days").val(DateDiff($("#F_StartDate").val().replace(/-/g, '/'),$("#F_EndDate").val().replace(/-/g, '/'))+1);

                   }

            }
         function DateDiff(sDate, eDate) { //sDate和eDate是yyyy-MM-dd格式
      var date1 = new Date(sDate);
      var date2 = new Date(eDate);
      var date3=date2.getTime()-date1.getTime();
      var days=Math.floor(date3/(24*3600*1000));
      return days;
    }
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">工号</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_UserNum" name="F_UserNum" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input" onclick="search('人员')">
                        <input type="text" id="F_UserId" name="F_UserId" hidden >

                    </div>
               </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">姓名</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_RealName" name="F_RealName" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input">
                   </div>
               </div>
             
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">类型</label>
                   <div class="layui-input-block">
                        <select id="F_HolidayTypeId" name="F_HolidayTypeId" lay-verify="required" lay-search="">
                            <option value="">==请选择==</option>
                        </select>
                   </div>
               </div>
               
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">开始时间</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_StartDate" name="F_StartDate" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input" >
                   </div>
               </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">结束时间</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_EndDate" name="F_EndDate" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input"  >
                   </div>
               </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">天数</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_Days" name="F_Days" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input" onclick="change()">
                   </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label ">请假原因</label>
                    <div class="layui-input-block">
                        <textarea id="F_Description" name="F_Description"  placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>
               
                
               
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>

